<!DOCTYPE HTML>
<html lang="en">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="Egg Vue SSR, Egg Vue CSR, Egg Vue Server Side Render,Egg Vue SSR/CSR 工程方案-快速开始, 前端工程化, node, egg, webpack, easywebpack, ves, res, ssr, react server side render, vue server side render">
    <meta name="description" content="Egg Vue SSR/CSR 工程方案,基于 Egg + Vue + Webpack 服务端渲染开发指南1. 项目初始化1.1 easywebpack-cli 脚手架初始化项目安装脚手架 npm install easywebpack-cli -g 命令行，然后就可以使用 easywebpack 或 easy 命令命令行运行 eas...">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>Egg Vue SSR/CSR 工程方案-快速开始 | easy-team</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery-2.2.0.min.js"></script>
    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper head-container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">easy-team</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>Home</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/res" class="waves-effect waves-light">
      
      <i class="fas fa-forward" style="zoom: 0.6;"></i>
      
      <span>Res</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/ves" class="waves-effect waves-light">
      
      <i class="fas fa-forward" style="zoom: 0.6;"></i>
      
      <span>Ves</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="" class="waves-effect waves-light">

      
      <i class="fas fa-list" style="zoom: 0.6;"></i>
      
      <span>Egg</span>
      <i class="fas fa-chevron-down" aria-hidden="true" style="zoom: 0.6;"></i>
    </a>
    <ul class="sub-nav menus_item_child ">
      
      <li>
        <a href="/egg-react">
          
          <i class="fas fa-forward" style="margin-top: -20px; zoom: 0.6;"></i>
          
          <span>Egg+React</span>
        </a>
      </li>
      
      <li>
        <a href="/egg-vue">
          
          <i class="fas fa-forward" style="margin-top: -20px; zoom: 0.6;"></i>
          
          <span>Egg+Vue</span>
        </a>
      </li>
      
    </ul>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/easywebpack" class="waves-effect waves-light">
      
      <i class="fas fa-building" style="zoom: 0.6;"></i>
      
      <span>Webpack</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog" class="waves-effect waves-light">
      
      <i class="fas fa-hacker-news" style="zoom: 0.6;"></i>
      
      <span>Blog</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>About</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>Contact</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="Search" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">easy-team</div>
        <div class="logo-desc">
            
            Node, 前端工程化, 多端技术
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			Home
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/res" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-forward"></i>
			
			Res
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/ves" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-forward"></i>
			
			Ves
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="javascript:;">
			
				<i class="fa-fw fas fa-list"></i>
			
			Egg
			<span class="m-icon"><i class="fas fa-chevron-right"></i></span>
		</a>
            <ul  style="background:  ;" >
              
                <li>   
				
                  <a href="/egg-react " style="margin-left:75px";>
				  
				   <i class="fa fas fa-forward" style="position: absolute;left:50px" ></i>
			      
		          <span>Egg+React</span>
                  </a>
                </li>
              
                <li>   
				
                  <a href="/egg-vue " style="margin-left:75px";>
				  
				   <i class="fa fas fa-forward" style="position: absolute;left:50px" ></i>
			      
		          <span>Egg+Vue</span>
                  </a>
                </li>
               
            </ul>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/easywebpack" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-building"></i>
			
			Webpack
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-hacker-news"></i>
			
			Blog
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			About
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			Contact
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/easy-team" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/easy-team" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    <div class="bg-cover pd-header" style="height: 9vh">
    <div class="container"></div>
</div>


    <script>
        // 每天切换 banner 图.  Switch banner image every day.
        $('.bg-cover').css('background-image', 'url(/medias/banner/' + new Date().getDay() + '.jpg)');
    </script>
    

<div class="doc-content">
    
     <div class="doc-left-nav" style="width:">
        <div class="side-nav docsidenav" style="width:">
    <div class="doc-left-nav-title">egg-vue</div>
    <ul class="menu-list mobile-menu-list">
        
            
                <li class="m-nav-item m-nav-show">
                    <a href="javascript:;">
                        <i class="fas fa-fw fa-link"></i>
                        开发指南
                        <span class="m-icon"><i class="fas fa-chevron-right"></i></span>
                    </a>
                    <ul  style="display:block; background:  ;" >
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-init" href="/egg-vue/init " 
                                    style="padding-left:75px";>
                                
                                <span>快速开始</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-start" href="/egg-vue/start " 
                                    style="padding-left:75px";>
                                
                                <span>从零开始</span>
                                </a>
                            </li>
                         
                    </ul>
                </li>
            
        
            
                <li class="m-nav-item m-nav-show">
                    <a href="javascript:;">
                        <i class="fas fa-fw fa-link"></i>
                        渲染模式
                        <span class="m-icon"><i class="fas fa-chevron-right"></i></span>
                    </a>
                    <ul  style="display:block; background:  ;" >
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-node" href="/egg-vue/node " 
                                    style="padding-left:75px";>
                                
                                <span>服务端渲染模式</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-web" href="/egg-vue/web " 
                                    style="padding-left:75px";>
                                
                                <span>前端渲染模式</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-html" href="/egg-vue/html " 
                                    style="padding-left:75px";>
                                
                                <span>HTML前端渲染</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-asset" href="/egg-vue/asset " 
                                    style="padding-left:75px";>
                                
                                <span>asset 渲染模式</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-fls9r6" href="/egg-vue/fls9r6 " 
                                    style="padding-left:75px";>
                                
                                <span>自定义前端渲染</span>
                                </a>
                            </li>
                         
                    </ul>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-vue/online" class="waves-effect waves-light" id="m-nav-item-egg-vue-online">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        部署流程
                    </a>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-vue/config" class="waves-effect waves-light" id="m-nav-item-egg-vue-config">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        配置说明
                    </a>
                </li>
            
        
            
                <li class="m-nav-item m-nav-show">
                    <a href="javascript:;">
                        <i class="fas fa-fw fa-link"></i>
                        特性支持
                        <span class="m-icon"><i class="fas fa-chevron-right"></i></span>
                    </a>
                    <ul  style="display:block; background:  ;" >
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-qpeiow" href="/egg-vue/qpeiow " 
                                    style="padding-left:75px";>
                                
                                <span>入口实现</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-async" href="/egg-vue/async " 
                                    style="padding-left:75px";>
                                
                                <span>异步加载</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-seo" href="/egg-vue/seo " 
                                    style="padding-left:75px";>
                                
                                <span>SEO实现</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-typescript" href="/egg-vue/typescript " 
                                    style="padding-left:75px";>
                                
                                <span>TypeScript</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-pwa" href="/egg-vue/pwa " 
                                    style="padding-left:75px";>
                                
                                <span>Service Worker</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-i18n" href="/egg-vue/i18n " 
                                    style="padding-left:75px";>
                                
                                <span>i18n 国际化支持</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-vue-babel" href="/egg-vue/babel " 
                                    style="padding-left:75px";>
                                
                                <span>Babel 构建优化</span>
                                </a>
                            </li>
                         
                    </ul>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-vue/version" class="waves-effect waves-light" id="m-nav-item-egg-vue-version">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        插件使用
                    </a>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-vue/about" class="waves-effect waves-light" id="m-nav-item-egg-vue-about">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        相关问题
                    </a>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-vue/case" class="waves-effect waves-light" id="m-nav-item-egg-vue-case">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        项目一览
                    </a>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-vue/open" class="waves-effect waves-light" id="m-nav-item-egg-vue-open">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        社区作品
                    </a>
                </li>
            
        
        <li><div class="divider"></div></li>
        
        <li>
            <a href="https://yuque.com/easy-team/egg-vue" class="waves-effect waves-light" target="_blank">
                <i class="fas fa-fw fa-link"></i>语雀文档
            </a>
        </li>
        <li>
            <a href="https://github.com/easy-team/egg-vue-webpack-boilerplate" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Github
            </a>
        </li>
    </ul>
</div>

     </div>
    
    <div class="doc-right-nav">
        <div class="card" class="doc-right-card">
            <div class="card-content article-info">
                <h1 style="margin-top: 12px; text-align: center;">快速开始</h1>
                
                <div class="post-info">
                    <div class="post-date info-break-policy">
                        <i class="far fa-calendar-minus fa-fw"></i>Date:&nbsp;&nbsp;
                        2019-10-20
                    </div>
    
                    
                        
                        <div class="info-break-policy">
                            <i class="far fa-file-word fa-fw"></i>Word Count:&nbsp;&nbsp;
                            2.3k
                        </div>
                        
    
                        
                        <div class="info-break-policy">
                            <i class="far fa-clock fa-fw"></i>Read Times:&nbsp;&nbsp;
                            10 Min
                        </div>
                        
                    
                    
                    
                        <div id="busuanzi_container_page_pv" class="info-break-policy">
                            <i class="far fa-eye fa-fw"></i>Read Count:&nbsp;&nbsp;
                            <span id="busuanzi_value_page_pv"></span>
                        </div>
                    
                </div>
            </div>
            <hr class="clearfix" style="margin: 0px 0px;">
            <div class="card-content article-card-content" style="padding-top: 0px;">
                <div id="articleContent">
                    <h3 id="基于-Egg-Vue-Webpack-服务端渲染开发指南"><a href="#基于-Egg-Vue-Webpack-服务端渲染开发指南" class="headerlink" title="基于 Egg + Vue + Webpack 服务端渲染开发指南"></a>基于 Egg + Vue + Webpack 服务端渲染开发指南</h3><h2 id="1-项目初始化"><a href="#1-项目初始化" class="headerlink" title="1. 项目初始化"></a>1. 项目初始化</h2><h3 id="1-1-easywebpack-cli-脚手架初始化项目"><a href="#1-1-easywebpack-cli-脚手架初始化项目" class="headerlink" title="1.1 easywebpack-cli 脚手架初始化项目"></a>1.1 <a href="https://github.com/easy-team/easywebpack-cli" target="_blank" rel="noopener">easywebpack-cli</a> 脚手架初始化项目</h3><ol>
<li><p>安装脚手架 <code>npm install easywebpack-cli -g</code> 命令行，然后就可以使用 <code>easywebpack</code> 或 <code>easy</code> 命令</p>
</li>
<li><p>命令行运行 <code>easywebpack init</code></p>
</li>
<li><p>选择 egg+vue server side render boilerplate 初始化骨架项目</p>
</li>
<li><p>安装依赖 <code>npm install</code></p>
</li>
</ol>
<h3 id="1-2-GitHub-仓库代码初始化项目"><a href="#1-2-GitHub-仓库代码初始化项目" class="headerlink" title="1.2 GitHub 仓库代码初始化项目"></a>1.2 GitHub 仓库代码初始化项目</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">git</span> clone https://github.com/hubcarl/egg-vue-webpack-boilerplate.git
<span class="token function">npm</span> <span class="token function">install</span></code></pre>
<p>初始化的项目提供多页面和SPA(vue-router/axios)服务端渲染实例，可以直接运行。</p>
<h3 id="1-3-vscode-插件初始化项目"><a href="#1-3-vscode-插件初始化项目" class="headerlink" title="1.3 vscode 插件初始化项目"></a>1.3 vscode 插件初始化项目</h3><p><a href="https://marketplace.visualstudio.com/items?itemName=hubcarl.vscode-easy-plugin#overview" target="_blank" rel="noopener">https://marketplace.visualstudio.com/items?itemName=hubcarl.vscode-easy-plugin#overview</a></p>
<h2 id="2-项目运行"><a href="#2-项目运行" class="headerlink" title="2. 项目运行"></a>2. 项目运行</h2><h3 id="2-1-本地运行"><a href="#2-1-本地运行" class="headerlink" title="2.1 本地运行"></a>2.1 本地运行</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">npm</span> run dev   // egg-bin dev</code></pre>
<p>npm run dev 做了如下三件事情</p>
<ul>
<li><p>启动 egg 应用</p>
</li>
<li><p>启动 Webpack 构建, 文件不落地磁盘，构建的文件都在内存里面(只在本地启动, 发布模式是提前构建好文件到磁盘)</p>
</li>
<li><p>构建会同时启动两个 Webpack 构建服务, 客户端js构建端口9000, 服务端端口9001</p>
</li>
<li><p>构建完成，Egg应用正式可用，自动打开浏览器</p>
</li>
</ul>
<h3 id="2-2-发布模式"><a href="#2-2-发布模式" class="headerlink" title="2.2 发布模式"></a>2.2 发布模式</h3><ul>
<li>构建文件落地磁盘</li>
</ul>
<pre class=" language-bash"><code class="language-bash"><span class="token function">npm</span> run build 或 easy build prod</code></pre>
<ol>
<li><p>启动 Webpack 构建，文件落地磁盘</p>
</li>
<li><p>服务端构建的文件放到 <code>app/view</code> 目录</p>
</li>
<li><p>前端构建的文件放到 <code>public</code> 目录</p>
</li>
<li><p>生成的 <code>manifest.json</code> 放到 <code>config</code> 目录</p>
</li>
<li><p>构建的文件都是 gitignore 的，<strong>部署时请注意把这些文件打包进去</strong></p>
</li>
</ol>
<ul>
<li>运行</li>
</ul>
<blockquote>
<p>非  <code>egg-scripts start</code>   方式启动时， 启动应用前， 请设置 <code>EGG_SERVER_ENV</code> 环境变量，测试环境设置 <code>test</code>， 正式环境设置 <code>prod</code></p>
</blockquote>
<pre class=" language-bash"><code class="language-bash"><span class="token function">npm</span> start  // egg-scripts start</code></pre>
<h2 id="3-项目构建"><a href="#3-项目构建" class="headerlink" title="3. 项目构建"></a>3. 项目构建</h2><ul>
<li><p>通过 <code>easywebpack-cli</code> 统一构建，支持 dev，test，prod 模式构建</p>
</li>
<li><p><code>easywebpack-cli</code> 通过项目根目录下的 <code>webpack.config.js</code> 配置文件构造出 Webpack 实际的配置文件，配置项请见 <a href="https://easy-team.github.io/easywebpack/config">webpack.config.js</a></p>
</li>
<li><p>获取 Webpack 实际的配置文件, <a href="https://github.com/easy-team/egg-webpack" target="_blank" rel="noopener">egg-webpack</a> 会使用到该功能。构建会根据 <code>webpackConfigList.length</code> 启动对应个数的 Webpack 编译实例，这里会同时启动两个 Webpack 构建服务, 客户端jsbundle构建，端口9000, 服务端jsbundle构建端口9001。默认端口为9000, 端口依次递增。</p>
</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript"><span class="token comment" spellcheck="true">// config/config.local.js 本地 npm start 使用</span>
<span class="token keyword">const</span> EasyWebpack <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'easywebpack-vue'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
exports<span class="token punctuation">.</span>webpack <span class="token operator">=</span> <span class="token punctuation">{</span>
  webpackConfigList<span class="token punctuation">:</span>EasyWebpack<span class="token punctuation">.</span><span class="token function">getWebpackConfig</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>
<ul>
<li>该项目中，<code>app/web/page</code> 目录中所有 .vue 文件当作 Webpack 构建入口是采用 app/web/framework/vue/entry 的 <strong>client-loader.js</strong> 和 *<em>server-loader.js *</em>模板实现的，这个需要结合 <code>webpack.config.js</code> 下的 entry.loader 使用。 骨架最新版本已被下面 <a href="https://github.com/isaacs/node-glob" target="_blank" rel="noopener">node-glob</a> 模式所替换。 这种方式可以自定义 entry 初始化模板。</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">entry<span class="token punctuation">:</span> <span class="token punctuation">{</span>
   include<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'app/web/page'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
   exclude<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'app/web/page/[a-z]+/component'</span><span class="token punctuation">,</span> <span class="token string">'app/web/page/app'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
   loader<span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token comment" spellcheck="true">// 如果没有配置loader模板，默认使用 .js 文件作为构建入口</span>
      client<span class="token punctuation">:</span> <span class="token string">'app/web/framework/vue/entry/client-loader.js'</span><span class="token punctuation">,</span>
      server<span class="token punctuation">:</span> <span class="token string">'app/web/framework/vue/entry/server-loader.js'</span><span class="token punctuation">,</span>
   <span class="token punctuation">}</span>    
<span class="token punctuation">}</span></code></pre>
<ul>
<li>使用 <a href="https://github.com/isaacs/node-glob" target="_blank" rel="noopener">node-glob</a> 遍历文件。下面配置会自动遍历 <code>app/web/page</code>  目录的所有 vue 文件作为 entry 入口，排除 <code>component|components|view|views</code> 目录下的文件。 这个是 <a href="https://github.com/easy-team/egg-vue-webpack-boilerplate" target="_blank" rel="noopener">egg vue ssr </a> 项目默认配置,  同时使用 <a href="https://github.com/easy-team/vue-entry-loader" target="_blank" rel="noopener">vue-entry-loader</a>  作为模板入口 。<a href="mailto:easywebpack@4.8.0" target="_blank" rel="noopener">easywebpack@4.8.0</a> 开始支持，因为有了默认配置，所以最新的骨架项目中，webpack.config.js 文件为非必须配置。</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript"><span class="token comment" spellcheck="true">// webpack.config.js</span>
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// 注意 只有 entry 文件是 .vue 文件(非.js）时，才会自动使用 vue-entry-loader 模板</span>
  entry<span class="token punctuation">:</span> <span class="token string">'app/web/page/**!(component|components|view|views)/*.vue'</span>
<span class="token punctuation">}</span></code></pre>
<h2 id="4-项目规范"><a href="#4-项目规范" class="headerlink" title="4. 项目规范"></a>4. 项目规范</h2><ul>
<li><p><a href="https://eggjs.org/zh-cn/basics/structure.html" target="_blank" rel="noopener">遵循 egg 开发规范</a></p>
</li>
<li><p>Vue 项目代码放到 app/web 目录，页面入口目录为 page，该目录的 所有 vue 文件默认会作为 Webpack 的 entry 构建入口。建议每个页面目录的只保留一个vue文件，vue关联的组件可以放到widget 或者 compnent目录。如果非要放到当前目录，请配置 <code>webpack.config.js</code> entry.exclude 排除 vue文件。</p>
</li>
</ul>
<p><img src="https://cdn.yuque.com/yuque/0/2018/png/116733/1528521398498-da1702b8-03e0-455b-8efc-b1ebb005abf3.png#width=234" alt=""></p>
<h2 id="5-项目开发"><a href="#5-项目开发" class="headerlink" title="5. 项目开发"></a>5. 项目开发</h2><p>支持多页面/单页面服务端渲染, 前端渲染, 静态页面三种方式.</p>
<h3 id="5-1-多页面服务端渲染实现"><a href="#5-1-多页面服务端渲染实现" class="headerlink" title="5.1 多页面服务端渲染实现"></a>5.1 多页面服务端渲染实现</h3><h4 id="5-1-1-多页面前端页面实现"><a href="#5-1-1-多页面前端页面实现" class="headerlink" title="5.1.1 多页面前端页面实现"></a>5.1.1 多页面前端页面实现</h4><p>在app/web/page 目录下面创建home目录, home.vue 文件, Webpack自动根据.vue文件创建entry入口, 具体实现请见<a href="https://easy-team.github.io/easywebpack/config">webpack.config.js</a></p>
<ul>
<li>home.vue 编写界面逻辑, 根元素为layout(自定义组件, 全局注册, 统一的html, meta, header, body, 你可以自定义 title，description，keywords SEO信息，更多信息请扩展layout).</li>
</ul>
<pre class=" language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>layout</span> <span class="token attr-name">title</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>基于egg-vue-webpack-dev和egg-view-vue插件的工程示例项目<span class="token punctuation">"</span></span> <span class="token attr-name">description</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>vue server side render<span class="token punctuation">"</span></span> <span class="token attr-name">keywords</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>egg, vue, webpack, server side render<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
   {{message}}
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>layout</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">></span></span><span class="token style language-css">
  <span class="token atrule"><span class="token rule">@import</span> <span class="token string">"home.css"</span><span class="token punctuation">;</span></span>
</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/babel<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token script language-javascript">

  <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    components<span class="token punctuation">:</span> <span class="token punctuation">{</span>

    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    computed<span class="token punctuation">:</span> <span class="token punctuation">{</span>

    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>

    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function">mounted</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span></code></pre>
<h4 id="5-1-2-多页面后端渲染实现-通过-egg-view-vue-ssr-插件-render-方法实现"><a href="#5-1-2-多页面后端渲染实现-通过-egg-view-vue-ssr-插件-render-方法实现" class="headerlink" title="5.1.2 多页面后端渲染实现, 通过 egg-view-vue-ssr 插件 render 方法实现"></a>5.1.2 多页面后端渲染实现, 通过 <code>egg-view-vue-ssr</code> 插件 <code>render</code> 方法实现</h4><ul>
<li>创建controller文件home.js</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">exports<span class="token punctuation">.</span>index <span class="token operator">=</span> <span class="token keyword">function</span><span class="token operator">*</span> <span class="token punctuation">(</span>ctx<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">yield</span> ctx<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span><span class="token string">'home/home.js'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> message<span class="token punctuation">:</span> <span class="token string">'vue server side render!'</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>
<ul>
<li>添加路由配置</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">app<span class="token punctuation">.</span><span class="token keyword">get</span><span class="token punctuation">(</span><span class="token string">'/home'</span><span class="token punctuation">,</span> app<span class="token punctuation">.</span>controller<span class="token punctuation">.</span>home<span class="token punctuation">.</span>index<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h4 id="5-1-3-多页面走前端渲染-后端路由-实现-通过-egg-view-vue-ssr-插件-renderClient-方法实现"><a href="#5-1-3-多页面走前端渲染-后端路由-实现-通过-egg-view-vue-ssr-插件-renderClient-方法实现" class="headerlink" title="5.1.3 多页面走前端渲染(后端路由)实现, 通过 egg-view-vue-ssr 插件 renderClient 方法实现"></a>5.1.3 多页面走前端渲染(后端路由)实现, 通过 <code>egg-view-vue-ssr</code> 插件 <code>renderClient</code> 方法实现</h4><ul>
<li>创建controller文件home.js</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">exports<span class="token punctuation">.</span>client <span class="token operator">=</span> <span class="token keyword">function</span><span class="token operator">*</span> <span class="token punctuation">(</span>ctx<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">yield</span> ctx<span class="token punctuation">.</span><span class="token function">renderClient</span><span class="token punctuation">(</span><span class="token string">'home/home.js'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> message<span class="token punctuation">:</span> <span class="token string">'vue server side render!'</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>
<ul>
<li>添加路由配置</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">app<span class="token punctuation">.</span><span class="token keyword">get</span><span class="token punctuation">(</span><span class="token string">'/client'</span><span class="token punctuation">,</span> app<span class="token punctuation">.</span>controller<span class="token punctuation">.</span>home<span class="token punctuation">.</span>home<span class="token punctuation">.</span>client<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h3 id="5-2-HTML静态页面前端渲染"><a href="#5-2-HTML静态页面前端渲染" class="headerlink" title="5.2 HTML静态页面前端渲染"></a>5.2 HTML静态页面前端渲染</h3><ul>
<li><p>直接有easywebpack构建出静态HTML文件, 请见 <code>webpack.config.js</code> 配置和 <code>app/web/page/html</code>代码实现</p>
</li>
<li><p>通过 <code>egg-static</code> 静态文件访问HTML文件</p>
</li>
</ul>
<h3 id="5-3-单页面服务器渲染同构实现"><a href="#5-3-单页面服务器渲染同构实现" class="headerlink" title="5.3 单页面服务器渲染同构实现"></a>5.3 单页面服务器渲染同构实现</h3><h4 id="5-3-1-单页面前端实现"><a href="#5-3-1-单页面前端实现" class="headerlink" title="5.3.1 单页面前端实现"></a>5.3.1 单页面前端实现</h4><p>在app/web/page 目录下面创建app目录, app.vue, app.js 文件.</p>
<ul>
<li>app.vue 编写界面逻辑, 根元素为layout(自定义组件, 全局注册, 统一的html, meta, header, body)</li>
</ul>
<pre class=" language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>app-layout</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>transition</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>fade<span class="token punctuation">"</span></span> <span class="token attr-name">mode</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>out-in<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>router-view</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>router-view</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>transition</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>app-layout</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>sass<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token style language-css">

</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/babel<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token script language-javascript">
  <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    computed<span class="token punctuation">:</span> <span class="token punctuation">{</span>

    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function">mounted</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>

    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span></code></pre>
<ul>
<li>app.js 页面调用入口</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript"><span class="token keyword">import</span> <span class="token punctuation">{</span> sync <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vuex-router-sync'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> store <span class="token keyword">from</span> <span class="token string">'store/app'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> router <span class="token keyword">from</span> <span class="token string">'component/app/router'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> app <span class="token keyword">from</span> <span class="token string">'./app.vue'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> App <span class="token keyword">from</span> <span class="token string">'app'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> Layout <span class="token keyword">from</span> <span class="token string">'component/layout/app'</span><span class="token punctuation">;</span>

App<span class="token punctuation">.</span><span class="token function">component</span><span class="token punctuation">(</span>Layout<span class="token punctuation">.</span>name<span class="token punctuation">,</span> Layout<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token function">sync</span><span class="token punctuation">(</span>store<span class="token punctuation">,</span> router<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> App<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  base<span class="token punctuation">:</span> <span class="token string">'/app'</span><span class="token punctuation">,</span>
  <span class="token operator">...</span>app<span class="token punctuation">,</span>
  router<span class="token punctuation">,</span>
  store
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h4 id="5-3-2-单页面后端实现"><a href="#5-3-2-单页面后端实现" class="headerlink" title="5.3.2 单页面后端实现"></a>5.3.2 单页面后端实现</h4><ul>
<li>创建controller文件app.js</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">exports<span class="token punctuation">.</span>index <span class="token operator">=</span> <span class="token keyword">function</span><span class="token operator">*</span> <span class="token punctuation">(</span>ctx<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">yield</span> ctx<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span><span class="token string">'app/app.js'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> url<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>url<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex">/\/app/</span><span class="token punctuation">,</span> <span class="token string">''</span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>
<ul>
<li>添加路由配置</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">app<span class="token punctuation">.</span><span class="token keyword">get</span><span class="token punctuation">(</span><span class="token string">'/app(/.+)?'</span><span class="token punctuation">,</span> app<span class="token punctuation">.</span>controller<span class="token punctuation">.</span>app<span class="token punctuation">.</span>app<span class="token punctuation">.</span>index<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h2 id="6-项目部署"><a href="#6-项目部署" class="headerlink" title="6. 项目部署"></a>6. 项目部署</h2><ul>
<li><p>正式环境部署，请设置 <code>EGG_SERVER_ENV=prod</code> 环境变量, 更多请见<a href="https://eggjs.org/zh-cn/basics/env.html" target="_blank" rel="noopener">运行环境</a></p>
</li>
<li><p>构建的 <code>app/view</code> 目录, <code>public</code> 目录以及 <code>buildConfig.json</code> 和 <code>manifest.json</code>等文件, 都是 <code>gitignore</code> 的，部署时请注意把这些文件打包进去。</p>
</li>
</ul>
<h2 id="7-构建目录"><a href="#7-构建目录" class="headerlink" title="7. 构建目录"></a>7. 构建目录</h2><ul>
<li><p>Webpack构建服务端(Node) JSBundle运行文件, 构建的服务端渲染模板文件位置 <code>${app_root}/app/view</code></p>
</li>
<li><p>Webpack构建浏览器JSBundle运行文件, 构建的前端资源(js/css/image)文件位置 <code>${app_root}/public</code></p>
</li>
<li><p>Webpack构建的 <code>manifest.json</code> 文件位置 <code>${app_root}/config</code> 目录</p>
</li>
<li><p>easywebpack-cli 构建配置文件 <code>webpack.config.js</code> 放到项目根目录<code>${app_root}/webpack.config.js</code></p>
</li>
<li><p>Vue代码文件<code>${app_root}/app/web</code> 下面, 主要包括 <code>asset</code>, <code>component</code>, <code>framework</code>, <code>page</code>, <code>store</code>, <code>view</code> 等目录</p>
</li>
</ul>
<pre><code>├── asset
│   ├── css
│   │   ├── normalize.css
│   │   └── style.css
│   ├── images
│   │   ├── favicon.ico
│   │   ├── loading.gif
│   │   └── logo.png
├── component
│   ├── app
│   │   ├── detail.vue
│   │   ├── list.vue
│   │   └── router.js
│   ├── layout
│   │   ├── app
│   │   │   ├── content
│   │   │   │   ├── content.css
│   │   │   │   └── content.vue
│   │   │   ├── footer
│   │   │   │   ├── footer.css
│   │   │   │   └── footer.vue
│   │   │   ├── header
│   │   │   │   ├── header.css
│   │   │   │   └── header.vue
│   │   │   ├── index.js
│   │   │   └── main.vue
├── framework
│   ├── inject
│   │   ├── global.css
│   │   ├── inline.js
│   │   └── pack-inline.js
│   └── vue
│       ├── app.js
│       ├── component
│       │   └── index.js
│       ├── directive
│       │   └── index.js
│       └── filter
│           └── index.js
├── page
│   ├── app
│   │   ├── app.js
│   │   └── app.vue
│   ├── index
│   │   ├── index.css
│   │   ├── index.js
│   │   └── index.vue
├── store
│   └── app
│       ├── actions.js
│       ├── getters.js
│       ├── index.js
│       ├── mutation-type.js
│       └── mutations.js
└── view
    └── layout.html</code></pre><h3 id="二-项目结构和基本规范"><a href="#二-项目结构和基本规范" class="headerlink" title="二. 项目结构和基本规范"></a>二. 项目结构和基本规范</h3><pre><code>├── app
│   ├── controller
│   │   ├── test
│   │   │   └── test.js
│   ├── extend
│   ├── lib
│   ├── middleware
│   ├── mocks
│   ├── proxy
│   ├── router.js
│   ├── view
│   │   ├── about                         // 服务器编译的jsbundle文件
│   │   │   └── about.js
│   │   ├── home
│   │   │     └── home.js                 // 服务器编译的jsbundle文件
│   │   └── layout.js                     // 编译的layout文件
│   └── web                               // 前端工程目录
│       ├── asset                         // 存放公共js,css资源
│       ├── framework                     // 前端公共库和第三方库
│       │   └── entry                          
│       │       ├── loader.js              // 根据jsx文件自动生成entry入口文件loader
│       ├── page                           // 前端页面和webpack构建目录, 也就是webpack打包配置entryDir
│       │   ├── home                       // 每个页面遵循目录名, js文件名, scss文件名, jsx文件名相同
│       │   │   ├── home.scss
│       │   │   ├── home.jsx
│       │   └── hello                      // 每个页面遵循目录名, js文件名, scss文件名, jsx文件名相同
│       │       ├── test.css               // 服务器render渲染时, 传入 render(&#39;test/test.js&#39;, data)
│       │       └── test.jsx
│       ├── store                             
│       │   ├── app
│       │   │   ├── actions.js
│       │   │   ├── getters.js
│       │   │   ├── index.js
│       │   │   ├── mutation-type.js
│       │   │   └── mutations.js
│       │   └── store.js
│       └── component                         // 公共业务组件, 比如loading, toast等, 遵循目录名, js文件名, scss文件名, jsx文件名相同
│           ├── loading
│           │   ├── loading.scss
│           │   └── loading.jsx
│           ├── test
│           │   ├── test.jsx
│           │   └── test.scss
│           └── toast
│               ├── toast.scss
│               └── toast.jsx
├── config
│   ├── config.default.js
│   ├── config.local.js
│   ├── config.prod.js
│   ├── config.test.js
│   └── plugin.js
├── doc
├── index.js
├── webpack.config.js                      // easywebpack-cli 构建配置
├── public                                 // webpack编译目录结构, render文件查找目录
│   ├── static
│   │   ├── css
│   │   │   ├── home
│   │   │   │   ├── home.07012d33.css
│   │   │   └── test
│   │   │       ├── test.4bbb32ce.css
│   │   ├── img
│   │   │   ├── change_top.4735c57.png
│   │   │   └── intro.0e66266.png
│   ├── test
│   │   └── test.js
│   └── vendor.js                         // 生成的公共打包库</code></pre><h2 id="8-项目和插件"><a href="#8-项目和插件" class="headerlink" title="8. 项目和插件"></a>8. 项目和插件</h2><ul>
<li><p><a href="https://github.com/easy-team/egg-vue-webpack-boilerplate" target="_blank" rel="noopener">egg-vue-webpack-boilerplate</a> 基于easywebpack-vue和egg-view-vue(ssr)插件的工程骨架项目</p>
</li>
<li><p><a href="https://github.com/easy-team/easywebpack-vue" target="_blank" rel="noopener">easywebpack-vue</a> Webpack Vue 构建工程化方案.</p>
</li>
<li><p><a href="https://github.com/easy-team/easywebpack-cli" target="_blank" rel="noopener">easywebpack-cli</a>  Webpack 构建工程化脚手架.</p>
</li>
<li><p><a href="https://github.com/easy-team/egg-view-vue-ssr" target="_blank" rel="noopener">egg-view-vue-ssr</a> egg vue ssr 解决方案.</p>
</li>
<li><p><a href="https://github.com/easy-team/egg-webpack" target="_blank" rel="noopener">egg-webpack</a> 本地开发热更新使用.</p>
</li>
<li><p><a href="https://github.com/easy-team/egg-webpack-vue" target="_blank" rel="noopener">egg-webpack-vue</a> 本地开发渲染内存读取辅助插件</p>
</li>
</ul>

                </div>
                <hr/>
    
                

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        Author:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://easy-team.github.io" rel="external nofollow noreferrer">sky</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        Link:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://easy-team.github.io/egg-vue/init/">https://easy-team.github.io/egg-vue/init/</a>
                </span>
            </div>
            <div class="reprint__type">
                    <span class="reprint-meta" style="font-weight: bold;">
                        <i class="fas fa-link">
                            yuque:
                        </i>
                    </span>
                    <span class="reprint-info">
                        <a href="https://yuque.com/easy-team/egg-vue/init/" target="_blank" rel="noopener">https://yuque.com/easy-team/egg-vue/init/</a>
                    </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        Reprint policy:
                    </i>
                </span>
                <span class="reprint-info">
                    All articles in this blog are used except for special statements
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    reprint polocy. If reproduced, please indicate source
                    <a href="https://easy-team.github.io" target="_blank">sky</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>Copied successfully, please follow the reprint policy of this article</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">more</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>


    
                <div class="tag_share" style="display: block; margin-top: 20px;">
                    <div class="post-meta__tag-list" style="display: inline-block;">
                        
                            
                        
                    </div>
                    <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                        <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    
    <div class="social-share" data-sites="qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                    </div>

                </div>
                
            </div>
        </div>
        
    
        
    
        
    
        
    
        
    
        

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;Previous</div>
            <div class="card">
                <a href="/egg-vue/html/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/14.jpg" class="responsive-img" alt="HTML前端渲染">
                        
                        <span class="card-title">HTML前端渲染</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            背景在 前端渲染模式 和 asset 渲染模式 章节讲到了基于 React 的前端渲染模式，但都依赖  egg-view-react-ssr 插件，那如何基于已有 egg 模板引擎 (egg-view-nunjucks 或 egg-view-ejs) + Webpack 完全自定义前端方案呢？...
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2019-10-20
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            sky
                            
                        </span>
                    </div>
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                Next&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/egg-vue/i18n/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/22.jpg" class="responsive-img" alt="i18n 国际化支持">
                        
                        <span class="card-title">i18n 国际化支持</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            在 Egg + Vue  SSR 方案中，可以使用 vue-i18n 实现国际化支持， 使用前请先阅读以下文档：http://kazupon.github.io/vue-i18n/guide/started.html#htmlhttp://kazupon.github.io/vue-i18n/guide/started.html#javascriptEgg + Vue 实现国际化安装依赖npm install vue-i18n --save 编写 cn 和 en 语言文件中文配置：egg-vue...
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2019-10-20
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            sky
                            
                        </span>
                    </div>
                </div>
                
            </div>
        </div>
        
    </div>
</article>

     </div>
</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('50')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + 'From: easy-team<br />'
            + 'Author: sky<br />'
            + 'Link: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->

<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>


<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>

    
<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>

<!-- menu-selected -->
<script>
    var pathname = location.pathname.replace(/^\//, '').replace(/\/$/, '').replace(/\//g, '-');
    $('#m-nav-item-' + pathname).addClass('doc-left-nav-mene-selected');
</script>

    <footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">年份</span>
            <a href="https://easy-team.github.io" target="_blank">sky</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/easy-team" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">106.5k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <span id="sitetime">载入运行时间...</span>
            <script>
                function siteTime() {
                    window.setTimeout("siteTime()", 1000);
                    var seconds = 1000;
                    var minutes = seconds * 60;
                    var hours = minutes * 60;
                    var days = hours * 24;
                    var years = days * 365;
                    var today = new Date();
                    var startYear = "2019";
                    var startMonth = "10";
                    var startDate = "20";
                    var startHour = "0";
                    var startMinute = "0";
                    var startSecond = "0";
                    var todayYear = today.getFullYear();
                    var todayMonth = today.getMonth() + 1;
                    var todayDate = today.getDate();
                    var todayHour = today.getHours();
                    var todayMinute = today.getMinutes();
                    var todaySecond = today.getSeconds();
                    var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                    var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                    var diff = t2 - t1;
                    var diffYears = Math.floor(diff / years);
                    var diffDays = Math.floor((diff / days) - diffYears * 365);
                    var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
                    var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
                        minutes);
                    var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours -
                        diffMinutes * minutes) / seconds);
                    if (startYear == todayYear) {
                        document.getElementById("year").innerHTML = todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffDays + " 天 " + diffHours +
                            " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    } else {
                        document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffYears + " 年 " + diffDays +
                            " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    }
                }
                setInterval(siteTime, 1000);
            </script>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/hubcarl" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:hubcarl@126.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=433207205" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 433207205" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>



    <a href="https://weibo.com/hubcarl" class="tooltipped" target="_blank" data-tooltip="关注我的微博: https://weibo.com/hubcarl" data-position="top" data-delay="50">
        <i class="fab fa-weibo"></i>
    </a>



    <a href="https://zhuanlan.zhihu.com/easywebpack" class="tooltipped" target="_blank" data-tooltip="关注我的知乎: https://zhuanlan.zhihu.com/easywebpack" data-position="top" data-delay="50">
        <i class="fab fa-zhihu1">知</i>
    </a>



    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;Search</span>
            <input type="search" id="searchInput" name="s" placeholder="Please enter a search keyword"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    

    <!-- Global site tag (gtag.js) - Google Analytics -->


    <!-- Baidu Analytics -->


    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        bp.async = true;
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    
    <script type="text/javascript" src="/libs/background/ribbon-dynamic.js" async="async"></script>
    
    
    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
